home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 8_6.lha / 8_6 / 8_6_filebuf.h < prev    next >
Text File  |  1993-08-08  |  771b  |  44 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / a streambuf tied to a file via stdio
  6. lass filebuf : public streambuf
  7.  
  8.    FILE *fp;        // stdio file pointer
  9.    char opened;    // mode of file
  10.  
  11. ublic:
  12.    int overflow(int c = EOF);
  13.    int underflow();
  14.  
  15.    // open a file and return 0 on failure
  16.    filebuf *open(const char *name, open_mode m);
  17.    int close();
  18.  
  19.    filebuf()
  20.    {
  21. opened = 0;
  22. fp = 0;
  23.    }
  24.  
  25.    // tie to already opened file
  26.    filebuf(FILE *nfp)
  27.    {
  28. opened = 1;
  29. fp = nfp;
  30.    }
  31.  
  32.    // tie to already opened file
  33.    // using the given buffer
  34.    filebuf(FILE *nfp, char *buf, int len) :
  35.        (buf, len)
  36.    {
  37. opened = 1;
  38. fp = nfp;
  39.    }
  40.  
  41.    ~filebuf()
  42.    { close(); }
  43. ;
  44.